package util

import (
	"github.com/op/go-logging"
	"os"
)

var logger = logging.MustGetLogger("example")

var format = logging.MustStringFormatter(
	`%{color}%{time:2006-01-02 15:04:05.000} %{level:.5s} ▶ %{shortfile} %{shortfunc} ▶ %{id:03x}%{color:reset} %{message}`,
)

// var fileFormat = logging.MustStringFormatter(
//     `%{time:2006-01-02 15:04:05.000} %{level:.4s} ▶ %{shortfunc} ▶ %{id:03x} %{message}`,
// )

// var fileFormat = logging.MustStringFormatter(
// 	`%{time:2006-01-02 15:04:05.000} %{level:.4s} ▶ %{shortfile} %{shortfunc} ▶ %{id:03x} %{callpath} %{message}`,
// )

func InitLogger() {
	consoleBackend := logging.NewLogBackend(os.Stderr, "", 0)
	consoleBackendLevel := logging.AddModuleLevel(consoleBackend)
	consoleBackendLevel.SetLevel(logging.DEBUG, "")
	consoleBackendFormatter := logging.NewBackendFormatter(consoleBackend, format)
	logging.SetBackend(consoleBackendFormatter)
}

func Logger() *logging.Logger {
	return logger
}
